<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var
include_once(dirname(__FILE__) . "/../tools/smarty/libs/Smarty.class.php");					//--> out template

include_once("impl/CategoryImpl.php");

require_once(dirname(__FILE__) . "/../controlHeader.php");					//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->
	

$oCatImpl 	= new CategoryImpl(DB_TAG_COUPON);		//--> Info Class

$error_message = '';
if(isset($_GET['page']))
	$page = $_GET['page'];
else 
	$page = 1;


$arrDataList = array();
$arrTmpStack = array();
$arrLevelStack = array();
$i = 0;
$k = 0;
$iDisCount = 500;
array_push($arrTmpStack,'0');

while(sizeof($arrTmpStack) > 0){
	$strtmp = array_pop($arrTmpStack);
	$i 		= array_pop($arrLevelStack);
	if($strtmp > 0){
		$oCat = $oCatImpl->getById($strtmp);
		if(is_object($oCat)){
			$tmp = '';
			for($j = 1; $j < $i; $j++){
				$tmp.='&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			$status = '';
			$iStart = ($page - 1) * $iDisCount;
			$iEnd	= $iStart + $iDisCount;
			
			if($k >= $iStart && $k < $iEnd){
				$oCat->level 	= $i;
				$oCat->name		= $tmp . $oCat->name;
				
				$arrDataList[] = $oCat;
//				$arrDataList[] = array("id" => $oCat->id, "isLeaf" => $oCat->isLeaf, "name" => $tmp . $oCat->name, "level" => $i);
			}
			
			$k++;
			if($k >= $iEnd)
				break;
		}
	}

	$sql = "SELECT id FROM category WHERE parentid='$strtmp' ORDER BY name";
	
	$mixBack = $oCatImpl->getColumns(DB_TAG_COUPON, $sql);
	if(is_array($mixBack)){
		$i++;
		foreach($mixBack as $catId){
			array_push($arrTmpStack, $catId);
			array_push($arrLevelStack,$i);
		}
	}
}


//$oCatImpl->mutilPager($objInfoClass->getCount(), $page, $iDisCount, '');

/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('error_message', $error_message);
$smarty->assign('backurl',$backurl);

$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('selfFileName', $selfFileName);
$smarty->assign('arrOperateInfo', $arrOperateInfo);

$smarty->assign('arrDataList', $arrDataList);
$smarty->assign('PAGE_BAR', $oCatImpl->pagenav);

$smarty->display('listClass.htm');
?>
